﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Mrsoft.SSC.AI;
using System.Data;
using System.Windows.Forms;

namespace Mrsoft.SSC
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            GetAll();
        }

        //private void GetAll()
        //{
        //    AI.AutoRecoginze ai = new AutoRecoginze();
        //    var card = ai.RecoginzeFromImage(@"C:\Users\Administrator\Desktop\9pKML7HXth.jpg");
        //    DAL.SecretCardDAL.SaveSecretCard(card);
        //}

        private void GetAll()
        {
            lbCardList.ItemsSource = DAL.SecretCardDAL.GetAllSecretCardId();
        }

        private void showCard()
        {
            var card = DAL.SecretCardDAL.GetSecretCardById(lbCardList.SelectedValue.ToString());
            txtImageName.Text = card.SerialId;
            #region A
            A1.Content = card.GetValue("1", "A");
            A2.Content = card.GetValue("2", "A");
            A3.Content = card.GetValue("3", "A");
            A4.Content = card.GetValue("4", "A");
            A5.Content = card.GetValue("5", "A");
            A6.Content = card.GetValue("6", "A");
            A7.Content = card.GetValue("7", "A");
            #endregion

            #region B
            B1.Content = card.GetValue("1", "B");
            B2.Content = card.GetValue("2", "B");
            B3.Content = card.GetValue("3", "B");
            B4.Content = card.GetValue("4", "B");
            B5.Content = card.GetValue("5", "B");
            B6.Content = card.GetValue("6", "B");
            B7.Content = card.GetValue("7", "B");
            #endregion

            #region C
            C1.Content = card.GetValue("1", "C");
            C2.Content = card.GetValue("2", "C");
            C3.Content = card.GetValue("3", "C");
            C4.Content = card.GetValue("4", "C");
            C5.Content = card.GetValue("5", "C");
            C6.Content = card.GetValue("6", "C");
            C7.Content = card.GetValue("7", "C");
            #endregion

            #region D

            D1.Content = card.GetValue("1", "D");
            D2.Content = card.GetValue("2", "D");
            D3.Content = card.GetValue("3", "D");
            D4.Content = card.GetValue("4", "D");
            D5.Content = card.GetValue("5", "D");
            D6.Content = card.GetValue("6", "D");
            D7.Content = card.GetValue("7", "D");
            #endregion

            #region E
            E1.Content = card.GetValue("1", "E");
            E2.Content = card.GetValue("2", "E");
            E3.Content = card.GetValue("3", "E");
            E4.Content = card.GetValue("4", "E");
            E5.Content = card.GetValue("5", "E");
            E6.Content = card.GetValue("6", "E");
            E7.Content = card.GetValue("7", "E");
            #endregion

            #region F
            F1.Content = card.GetValue("1", "F");
            F2.Content = card.GetValue("2", "F");
            F3.Content = card.GetValue("3", "F");
            F4.Content = card.GetValue("4", "F");
            F5.Content = card.GetValue("5", "F");
            F6.Content = card.GetValue("6", "F");
            F7.Content = card.GetValue("7", "F");
            #endregion

            #region G
            G1.Content = card.GetValue("1", "G");
            G2.Content = card.GetValue("2", "G");
            G3.Content = card.GetValue("3", "G");
            G4.Content = card.GetValue("4", "G");
            G5.Content = card.GetValue("5", "G");
            G6.Content = card.GetValue("6", "G");
            G7.Content = card.GetValue("7", "G");
            #endregion
        }

        private void lbCardList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            showCard();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDia = new OpenFileDialog();
            fileDia.Filter = "JPEG|*.JPG|BMP|*bmp";
            fileDia.ShowDialog();
            if (!string.IsNullOrEmpty(fileDia.FileName))
            {
                txtImageName.Text = fileDia.FileName;
                AI.AutoRecoginze ai = new AutoRecoginze();
                var card = ai.RecoginzeFromImage(fileDia.FileName);
                if (card.PasswordsList.Count == 49)
                {
                    DAL.SecretCardDAL.SaveSecretCard(card);
                    GetAll();
                }
            }

        }



    }
}
